﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace Tfs_analyzer.BaseValidators
{
  class ChangesetPerDayCountValidator: IChangesetValidator
  {
    IValidationResult IChangesetValidator.CheckChangeset(Changeset i_changeset_to_analyze, IEnumerable i_changesets)
    {
      ValidationResult res = new ValidationResult();
      int count = 0;
      foreach (Changeset chs in i_changesets)
      {
        if (chs.ChangesetId == i_changeset_to_analyze.ChangesetId)
          continue;

        if (chs.Owner != i_changeset_to_analyze.Owner)
          continue;


        if ((chs.CreationDate.Day == i_changeset_to_analyze.CreationDate.Day) && (chs.CreationDate.TimeOfDay < i_changeset_to_analyze.CreationDate.TimeOfDay))
          count++;  
      }

      if (count < 2)
        return null;

      res.SetMark(count * 2);
      res.SetReason(count.ToString() + " changeset on the same day by " + i_changeset_to_analyze.Owner.ToString());

      return res;
    }
  }
}
